﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Nirvana
{
    public static class DictionaryExtensions
    {
        public static void RemoveAll<K, V>(this Dictionary<K, V> dic, Func<K, V, bool> filter)
        {
            List<K> list = DictionaryKey<K>.GetKeys();
            foreach (KeyValuePair<K, V> keyValuePair in dic)
            {
                if (filter(keyValuePair.Key, keyValuePair.Value))
                {
                    list.Add(keyValuePair.Key);
                }
            }
            for (int i = 0; i < list.Count; i++)
            {
                dic.Remove(list[i]);
            }
            list.Clear();
        }
        private static class DictionaryKey<T>
        {
            public static List<T> GetKeys()
            {
                return DictionaryKey<T>.Keys;
            }

            private static List<T> Keys = new List<T>();
        }
    }
}


